var user  = require('../../utils/user.js')
var util  = require('../../utils/util.js')
var app   = getApp()
Page({
  data: {
    array: [{key:'',value:'全部'}, {key:'Beijing',value:'北京'}, {key:'Shanghai', value:'上海'}, {key:'Xian',value:'西安'}, {key:'Sanya',value:'三亚'}, {key:'Chengdu',value:'成都'}],
    index: 0,
    imgUrls: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
      'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
    ],
    late:1,
    start:'2017-01-01',
    end:'2019-01-01',
    sdate:null,
    edate:null,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000
  },
  
  bindPickerChange: function(e) {
    console.log(this.data.array[e.detail.value].key)
    
    this.setData({
      index: e.detail.value
    })
  },
  bindStartDateChange: function(e) {
    console.log(e.detail.value)
    //e.detail.value = e.detail.value < this.data.sdate ? this.data.sdate : e.detail.value
    this.setData({
      sdate: e.detail.value,
      late: util.dateDiff(e.detail.value, this.data.edate)
    })
  },
  bindEndDateChange: function(e) {
    console.log(e.detail.value)
    console.log(util.dateDiff(this.data.sdate, e.detail.value))
    //e.detail.value = e.detail.value < this.data.sdate ? this.data.sdate : e.detail.value
    this.setData({
      edate: e.detail.value,
      late: util.dateDiff(this.data.sdate, e.detail.value)

    })
  },
  formSubmit: function(e) {
    var that = this
    var sdate = e.detail.value.sdate
    var edate = e.detail.value.edate

    wx.navigateTo({
      url: '/pages/list/list?page=1&area=' + this.data.array[e.detail.value.area].key + '&sdate=' + sdate + '&edate=' + edate
    })

  },
  onLoad:function(options){
    app.getCarAllTypes();
    var that = this
    var date = new Date()
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()

    var sdate = [year, month, day].map(function(n){
      n = n.toString()
      return n[1] ? n : '0' + n
    }).join('-')
    that.setData({
      sdate : sdate,
      edate : sdate
    })
  },
  onShow:function(){
    this.setData({
      c:app.globalData.c
    })
    // 页面显示
    if (user.checkLogin()) {
      this.setData({login:true})
    }else{
      this.setData({login:false})
    }
  },
  makePhoneCall:function(){
    wx.makePhoneCall({
      phoneNumber: '4006721729',
      success:function(){},
      complete:function(){
        
      }
    })
  }
})